// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'
import store from './store/store.js'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/icon/iconfont.css'
import axios from './configs/api.js'
import Vuecookies from 'vue-cookies'
import commonUtil from './utils/commonUtil'
import global from './utils/global'
import echarts from 'echarts'
Vue.prototype.$axios = axios
Vue.prototype.commonUtil = commonUtil
Vue.prototype.global = global
Vue.prototype.$echarts = echarts 
Vue.config.productionTip = false
Vue.use(Vuex)
Vue.use(ElementUI)
Vue.use(Vuecookies)
/* eslint-disable no-new */
router.beforeEach((to, from, next) => {  
    //to即将进入的目标路由对象，from当前导航正要离开的路由， next : 下一步执行的函数钩子
    if(to.path === '/login') {
    	next() 
     } // 如果即将进入登录路由，则直接放行
     else {   //进入的不是登录路由
         if(to.meta.requiresAuth) {
         	if (window.$cookies.get("token")==null ||window.$cookies.get("token")=='null') {
         		next({ path: '/login' })
         	}else{
         		next() 
         	}
         }else { 
         	next() 
         }
     } 
    })

new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
